package core.util;

import cn.hutool.json.JSONUtil;
import lombok.Data;

import java.util.List;

/**
 * 购票请假工具
 * @author : Gong.Yang
 */
public class PlanUtile {


    private static double dailyWage = 460;

    /**
     * 节假日的开始时间下标
     */
    private static int holidayStart = 7;

    public static void main(String[] args) {
        List<DayInfo> data = getData();
        for (int i = 0; i < data.size(); i++) {
            double leavePrice = getLeavePrice(data, i, holidayStart, dailyWage);
            DayInfo dayInfo = data.get(i);
            dayInfo.setOverhead(dayInfo.getPrice() + leavePrice);
        }
        System.out.println(JSONUtil.toJsonStr(data));
    }

    private static double getLeavePrice(List<DayInfo> data, int i, int holidayStart, double dailyWage) {
        if (i >= holidayStart) return 0;

        double leavePrice = 0;
        for (; i < holidayStart; i++) {
            double dayLeave = data.get(i).isHoliday() ? 0 : dailyWage;
            leavePrice += dayLeave;
        }
        return leavePrice;
    }


    static List<DayInfo> getData() {
        return List.of(
                new DayInfo(1000, false),
                new DayInfo(1400, true),
                new DayInfo(1200, false),
                new DayInfo(1300, false),
                new DayInfo(1400, false),
                new DayInfo(1900, false),
                new DayInfo(2000, false),
                new DayInfo(2500, true),
                new DayInfo(2500, true),
                new DayInfo(2500, true)
        );
    }


    @Data
    public static class DayInfo {
        private static int dayCount = 0;
        /**
         * 第几天
         */
        private int day;

        /**
         * 当天机票价格
         */
        private double price;

        /**
         * 当天是否是节假日
         */
        private boolean holiday;

        /**
         * 今天起飞的实际开销
         */
        private double overhead;

        public DayInfo(double price, boolean holiday) {
            this.day = ++dayCount;
            this.price = price;
            this.holiday = holiday;
        }
    }
}
